<?php if($this->errMsg) :?>
	<?php $this->showError($this->errMsg)?>
<?php endif; print_r($this->arrtypenews);?>

<script>
$(function() {
	var dates = $( "#fromday, #today" ).datepicker({
		defaultDate: "+1w",
		changeMonth: true,
		numberOfMonths: 3,
		onSelect: function( selectedDate ) {
			var option = this.id == "fromday" ? "minDate" : "maxDate",
				instance = $( this ).data( "datepicker" ),
				date = $.datepicker.parseDate(
					instance.settings.dateFormat ||
					$.datepicker._defaults.dateFormat,
					selectedDate, instance.settings );
			dates.not( this ).datepicker( "option", option, date );
		}
	});
});
</script>

<div class="mydiv">
<form name='form' id='form' action="" method="POST">
	<div class="title_ad"><label><a href="">Danh sách bình luận</a></label>
	</div>
	<div class="div_button" >	
	<table>
		<tr>
			<td><label>From day :</label></td><td><input readonly="readonly" type="text" value="<?php echo $this->from;?>" name="fromday" id="fromday" ></td>
			<td><label>To day :</label></td><td><input readonly="readonly" type="text" value="<?php echo $this->to;?>" name="today" id="today"></td>
			<td><input type="submit" value="Tìm kiếm" class="button1"/></td>
		</tr>
	</table>
	</div>
</form>
	<table  class="display" id="list">
	<thead>
		<tr>
			<th>ID</th>
			<th>username/email</th>
			<th>Forum/date</th>
			<th>News Name/content</th>
			<th width="70px">Status</th>
			<th>Tool</th>
		</tr>
	</thead>
	<tbody>
	<?php
		foreach($this->data as $key=>$row)
		{ 
	?>
		<tr>
			<td width="60"><?php echo $row->id?></td>
			<td ><label style="color: #6E6E6E;"><?php echo $row->user;?></label><br/><lable><?php if(strlen($row->email)<=19) echo $row->email; else echo (substr($row->email,0,4)."<a href='javascript:showmail(\"".$row->email."\")'>...</a>".substr($row->email,-15))?></lable></td>
			<td><lable style="color: #6E6E6E;"><?php echo $row->forum."/".$row->name."</lable><br/><lable>".$row->date;?></lable></td>
			<td><lable style="color: #6E6E6E;"><?php echo $row->headLines;?></lable><br/><lable><?php echo $row->content?></lable></td>
			<td id="active_<?php echo $row->id?>">
				<?php
				if($row->status == 1)
					echo 'Hiện <a style="float:right;" href="javascript:hide('.$row->id.')" title="Ẩn comment này"><img src="'.$this->baseUrl().'/public/images/Unbanned.png"></img></a>';
				else
					echo 'Ẩn <a style="float: right;" href="javascript:show('.$row->id.')" title="Hiện comment này"><img src="'.$this->baseUrl().'/public/images/Banned.png"></img></a>';
				?>
			</td>			
			<td width="80">				
				<a href="javascript:del(<?php echo $row->id;?>)" title='Delete' class='delete'><img src="<?php echo $this->baseUrl()?>/public/images/delete-icon.png"></img></a>
			</td>
		</tr>		
	<?php
		} 		
	?>
	</tbody>
</table>
</div>

<script>
function hide(key){
	if(!confirm("bạn muốn ẩn comment này không?"))
		return;
	$.ajax({
		type: "POST",
		url:"<?php echo $this->baseUrl.'/admin/comment/status'?> ",
		data: "id=" + key +"&status=0",	
		success: function(msg){
			if(msg == "1")
			{	
				$('#active_'+key).html('Ẩn<a style="float: right;" href="javascript:show('+key+')" title="Hiện Comment này"><img src="<?php echo ($this->baseUrl().'/public/images/banned.png') ?>"></img></a>');
			}else
				alert('Error');
		}
	});
}

function show(key){
	if(!confirm("bạn muốn hiện comment này không?"))
		return;
	$.ajax({
		type: "POST",
		url:"<?php echo $this->baseUrl.'/admin/comment/status'?> ",
		data: "id=" + key +"&status=1",	
		success: function(msg){
			if(msg == "1")	
				$('#active_'+key).html('Hiện<a style="float: right;" href="javascript:hide('+key+')" title="Ẩn comment này"><img src="<?php echo ($this->baseUrl().'/public/images/Unbanned.png') ?>"></img></a>');
			else
				alert('Error');
		}
	});
}
function del(key){
	if(!confirm("Bạn muốn xóa comment này không?"))
		return;
	$.ajax({
		type: "POST",
		url:"<?php echo $this->baseUrl.'/admin/comment/delete'?> ",
		data: "id=" + key,	
		success: function(msg){
			if(msg == '1')
				location.replace("<?php echo $this->baseUrl.'/admin/comment/index'?>");
			else
				alert('Error');
		}
	});
}
function showmail(text)
{
	window.prompt ("Email đầy đủ : ", text);
}
</script>